package cn.ichiva.tushare.analysis.data;

import cn.ichiva.tushare.sdk.tushare.entity.TuTable;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 按日获取数据
 */
public interface DailyData {
    String[] findByDaily(String date);

    default List<String[]> findByDaily(List<String> dateList){
        return dateList.stream()
                .map(e -> this.findByDaily(e))
                .collect(Collectors.toList());
    }

    /**
     * 可见数据
     * @param date
     * @return
     */
    default String visibleDate(String date){
        return date;
    }

    static void smooth(TuTable tuTable) {
        String[][] items = tuTable.getItems();
        if (items.length == 0) {
            throw new RuntimeException("数据为空");
        }

        String[] pro = items[0];
        for (String item : pro) {
            if(null == item) throw new RuntimeException("数据其实位置缺失");
        }

        for (int i = 1; i < items.length; i++) {
            String[] item = items[i];
            for (int ii = 0; ii < item.length; ii++) {
                if(item[ii] == null){
                    item[ii] = pro[ii];
                }
            }
            pro = item;
        }
    }
}
